%{

#include <stdio.h>
#include <stdlib.h>
#include "hash.h"
#include "y.tab.h"

int lineNumber = 1;
int running = 1;

table symbolsTable;

void initMe(void) {
	initTable(&symbolsTable);
}

%}

%x COMM

%%

"word"						{  return KW_WORD;   }
"bool"						{  return KW_BOOL;   }
"byte"						{  return KW_BYTE;   }
"if"					    {  return KW_IF;     }
"then"						{  return KW_THEN;   }
"else"						{  return KW_ELSE;   }
"loop"						{  return KW_LOOP;   }
"input"						{  return KW_INPUT;  }
"output"					{  return KW_OUTPUT; }
"return"				    {  return KW_RETURN; }

["\-"","";"":""\(""\)""\[""\]""\{""\}""\+""\*""\/""\<""\>""=""!""&""\$"]					{   return yytext[0]; }

"\<="						{ return OPERATOR_LE;  }
"\>="						{ return OPERATOR_GE;  }
==							{ return OPERATOR_EQ;  }
!=							{ return OPERATOR_NE;  }
&&							{ return OPERATOR_AND;  }
"\|\|"						{ return OPERATOR_OR;  }


"FALSE"						{ 
								yylval.symbol = put(yytext, SYMBOL_LIT_FALSE, &symbolsTable); 
								return LIT_FALSE;  
							}
							
"TRUE"						{
								yylval.symbol = put(yytext, SYMBOL_LIT_TRUE, &symbolsTable);
								return LIT_TRUE;
						    }
						    
"false"						{ 
								yylval.symbol = put(yytext, SYMBOL_LIT_FALSE, &symbolsTable); 
								return LIT_FALSE;  
							}
							
"true"						{
								yylval.symbol = put(yytext, SYMBOL_LIT_TRUE, &symbolsTable);
								return LIT_TRUE;
						    }						    
						    

[a-zA-Z_][a-zA-Z0-9_]* 		{
								yylval.symbol = put(yytext, SYMBOL_IDENTIFIER, &symbolsTable);
								return TK_IDENTIFIER;
						    }


[0-9][0-9A-Fa-f]*			{
								yylval.symbol = put(yytext, SYMBOL_LIT_INTEGER, &symbolsTable);
 								return LIT_INTEGER;
  							}
  							
"'"."'"						{
								yylval.symbol = put(yytext, SYMBOL_LIT_CHAR, &symbolsTable);
 								return LIT_CHAR;
  							}

\"[^\"]*\"					{
								yylval.symbol = put(yytext, SYMBOL_LIT_STRING, &symbolsTable);
 								return LIT_STRING;
  							}



"//"[^"\n"]*"\n"					{lineNumber++;}	

"/*"	BEGIN(COMM);

<COMM>"*/"	BEGIN(INITIAL);
<COMM>.	        {}
<COMM>"\n"	{lineNumber++;}

"\n"						{lineNumber++;}
[ \t]+ 							   {}

[^ \t"\n"]							{ yylval.lineNumber=lineNumber; return TOKEN_ERROR; }


%%


int yywrap(){
	running = 0;
	return 1;
}
